#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<errno.h>
#include<unistd.h>
#include<string.h>
#include<sys/mman.h>

#define LCD_SIZE 800*480*4

int main(int argc, char const *argv[])
{
    //打开液晶屏
    int lcd_fd = open("/dev/fb0",O_RDWR);
    if(lcd_fd<0)
    {
        perror("open() fail");
        exit(EXIT_FAILURE);
    }
    //给LCD映射一块内存(显存)
    int *p = mmap(NULL,LCD_SIZE,PROT_WRITE | PROT_READ,MAP_SHARED,lcd_fd,0);

    int colors[3]={0x00FF00FF,0x00FF0000,0x0000FF00};
    int x,y;
    //设斜线满足方程y = x + 1
    for(y=0;y<480;y++)
    {
        for(x=0;x<800;x++)
        {
            if(x+1==y || x+2 ==y )
            {
                p[y*800 + x]=colors[1];
            }else{
                p[y*800 + x]=colors[2];
            }
        }
    }
    munmap(p,LCD_SIZE);
    close(lcd_fd);
    return 0;
}
